package com.lft.juc03.lock8;

import java.util.concurrent.TimeUnit;

/**
 * 线程8锁——锁5.
 * 修改 senSms() 为静态同步方法
 * 同步方法锁的是this，调用者是对象，静态同步方法的调用者是Class类唯一。
 */
public class Lock5 {
	public static void main(String[] args) {
		Phone5 phone = new Phone5();
		new Thread(() -> {phone.senSms();}, "A").start();
		try {TimeUnit.SECONDS.sleep(2);} catch (InterruptedException e) {e.printStackTrace();}
		new Thread(() -> {phone.call();}, "B").start();
	}
}

class Phone5 {
	public static synchronized void senSms() {
		// 新增Thread.sleep()给 senSms()
		try {TimeUnit.SECONDS.sleep(4);} catch (InterruptedException e) {e.printStackTrace();}
		System.out.println(Thread.currentThread().getName() + " 发短信");
	}
	
	public synchronized void call() {
		System.out.println(Thread.currentThread().getName() + " 打电话");
	}
}